from fastapi import FastAPI,BackgroundTasks
import uvicorn
import time

app = FastAPI()


def write_notification():
    time.sleep(20)
    print("我测试一下")

@app.get("/")
async def root():
    return {"message": "Hello World5"}

@app.get("/send-notification/")
async def send_notification(background_tasks: BackgroundTasks):
    background_tasks.add_task(write_notification)
    return {"message": "Notification sent in the background"}

if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)